<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Util\SqlServerUtil;
use Cookie;


class IndexController extends Controller
{
	
	protected $response = [
			"code" => 200,
			"message" => "接口请求成功",
			"result" => []
	];
	
	protected $SqlServer = null;
	
	public function __construct(Request $request){
		$temp = SqlServerUtil::getModel($request);
		if($temp){
			$this->SqlServer = $temp['SqlServer'];
		}
	}
	
	/* public function home(Request $request)
	{
		$auth = $request->cookie("wms_auth");
		
		return view('home')->with(['auth' => $auth]);
	} */
	
	public function index()
	{
		//return view('home');
	}
	
	public function login(Request $request){
		$username = $request->get("username");
		$password = $request->get("password");
		$sql ="select username,password from yd_admin where username='" . $username."' and password='" .$password ."'";
		$user = SqlServerUtil::exec($this->SqlServer,$sql);
		//$user = $this->checkMasterExUser($FName, $FSID);
		
		if($user && count($user)>0){
			$wms_auth = json_encode($user[0]);
			$request->session()->put("wms_auth",$wms_auth);
			Cookie::queue('wms_auth', $wms_auth, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = false);
			
			$this->response['result'] = $user[0];
			return response($this->response);
		}else{
			$this->response['code'] = 400;
			$this->response['message'] = "登录失败账号或者密码错误";
			return response()->json($this->response);
		}
		//dd($this->response);
		
	}
	
}